﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dhgms.TplHelper.Model.TaskHelper
{
    using Dhgms.TplHelper.Controller.Task;
    using Dhgms.TplHelper.Model.Info;
    using Dhgms.TplHelper.Model.Info.TaskResult;

    public abstract class DataScalarTaskHelper<TDatabaseScalarProducer, TTaskResultClass, TTaskDataType> : InternalTransformerTaskHelper<TTaskResultClass, TTaskDataType>
        where TDatabaseScalarProducer : Model.DatabaseScalarProducer.IDatabaseScalarProducer<TTaskDataType>
        where TTaskResultClass : TaskResultBase, IReportableCount, ITaskDataResult<TTaskDataType>, new()
    {
        protected DataScalarTaskHelper(string name)
            : base(name)
        {
        }

        protected override DataRetrievalProcessorResult<TTaskDataType> OnProcess()
        {
            var producer = GetProducer();

            var executionResult = producer.GetResult();

            var result = new DataRetrievalProcessorResult<TTaskDataType>(1, executionResult);
            return result;
        }

        /// <summary>
        /// Gets the producer.
        /// </summary>
        /// <returns>The producer</returns>
        protected abstract TDatabaseScalarProducer GetProducer();
    }
}
